
#if !defined __RT_PAIRINETADDR_H__
#define __RT_PAIRINETADDR_H__

#include "RtDefines.h"
#include "RtInetAddr.h"

class CRtPairInetAddr
{
public:
/*
	CRtPairInetAddr()
		: m_dwPeerIP(0)
		, m_wPeerPort(0)
		, m_dwLocalIP(0)
		, m_wLocalPort(0)
	{
	}

*/
	CRtPairInetAddr(const CRtInetAddr &aPeer, const CRtInetAddr &aLocal)
		: m_dwPeerIP(aPeer.GetPtr()->sin_addr.s_addr)
		, m_wPeerPort(aPeer.GetPtr()->sin_port)
		, m_dwLocalIP(aLocal.GetPtr()->sin_addr.s_addr)
		, m_wLocalPort(aLocal.GetPtr()->sin_port)
	{
		RT_ASSERTE(/*m_dwPeerIP && m_dwLocalIP &&*/ m_wPeerPort && m_wLocalPort);
	}

	DWORD GetHashValue() const 
	{
		// this hash function is copied from linux kernel
		// source code whose flie name is "net/ipv4/Tcp_ipv4.c".
		int h = ((m_dwPeerIP ^ m_wPeerPort) ^ (m_dwLocalIP ^ m_wLocalPort));
		h ^= h>>16;
		h ^= h>>8;
		return h;
	}

	bool operator == (const CRtPairInetAddr &aRight) const 
	{
		return m_dwPeerIP == aRight.m_dwPeerIP && 
			m_wPeerPort == aRight.m_wPeerPort && 
			m_dwLocalIP == aRight.m_dwLocalIP && 
			m_wLocalPort == aRight.m_wLocalPort;
	}

public:
	DWORD m_dwPeerIP;
	WORD m_wPeerPort;
	DWORD m_dwLocalIP;
	WORD m_wLocalPort;
};

#endif	//__RT_PAIRINETADDR_H__
